package cn.zhz.service.user;

import cn.zhz.dao.user.UserMapper;
import cn.zhz.pojo.User;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Transactional
@Service("userService")
public class UserServiceImpl implements UserService{

    @Resource
    private UserMapper userMapper;

    @Override
    public User login(String userCode, String userPassword) throws Exception {
        User user = null;
        user = userMapper.getLoginUser(userCode);
        //匹配密码
		/*if(null != user){
			if(!user.getUserPassword().equals(userPassword))
			    user = null;
		}*/
        return user;
    }

    @Override
    public int getUserCount(String queryUserName, int _queryUserRole) {
        int count = 0;
        System.out.println("queryUserName ---- > " + queryUserName);
        System.out.println("queryUserRole ---- > " + _queryUserRole);
        count = userMapper.getUserCount(queryUserName,_queryUserRole);
        return count;
    }

    @Override
    public List<User> getUserList(String queryUserName, int queryUserRole, int currentPageNo, int pageSize) {
            int beginIndex = (currentPageNo-1)*pageSize;
            return userMapper.getUserList(queryUserName, queryUserRole, beginIndex, pageSize);
    }

    @Override
    public int adduser(User user) {
            return userMapper.adduser(user);
    }

    @Override
    public User getUserById(String id) {
            return userMapper.getUserById(id);
    }

    @Override
    public Boolean modify(User user) {
            Boolean flag=false;
            if(userMapper.modify(user)>0){
                flag=true;
            }
            return flag;
    }

    @Override
    public User selectUserCodeExist(String userCode) {
        return null;
    }
}
